package gam.n1.areas.impl;

import gam.n1.achievement.n.IntegerAchievement;
import gam.n1.areas.Area;
import gam.n1.areas.a.TimingBaseBukkitArea;
import gam.n1.be.impl.SkillHandler;
import gam.n1.skills.Skill;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Predicate;

public abstract class SkillPlayBukkitArea extends TimingBaseBukkitArea {
    private final Set<Skill> skills; //此场所能用的技能
    private final SkillHandler handler;

    public SkillPlayBukkitArea(@NotNull Plugin plugin, @NotNull String key) throws Exception {
        super(plugin, key);
        this.skills = new HashSet<>();
        this.handler = new SkillHandler(this);
        behaviorals(Arrays.asList(handler));
        getAchievementManager().addRule(new IntegerAchievement(()->0,"SkillPlay")); //玩家使用技能次数
        getAchievementManager().addRule(new IntegerAchievement(()->0,"SkillKill")); // 使用技能击杀数
    }

    public void addSkill(Skill skill,@Nullable Predicate<Area> c){
        Objects.requireNonNull(skill);
        skills.add(skill);
        if (skill.isAuto() && c != null) handler.addAutoSkillRule(skill,c);
    }
//    @Override
//    public boolean cI() {
//        return super.cI()
//                && skills.size() > 0
//                ;
//    }

    public Set<Skill> getSkills() {
        return Collections.unmodifiableSet(skills);
    }
}
